package com.action.imp;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.action.*;
import com.bean.*;
import java.util.*;

import com.service.BizService;
import com.util.AjaxUtil;
@Controller
public class GoodsActionImp implements GoodsAction {
	@Autowired
	private BizService bizService;
	
	public BizService getBizService() {
		return bizService;
	}

	public void setBizService(BizService bizService) {
		this.bizService = bizService;
	}
	@RequestMapping(value="save_Goods.do")
	public String save(HttpServletResponse response,
			HttpServletRequest request, Goods goods) {
		int code=bizService.getGoodsBiz().save(goods);
		if(code>0){
			AjaxUtil.printString(response, ""+1);
		}else{
			AjaxUtil.printString(response, ""+0);
		}
		return null;
	}
	@RequestMapping(value="update_Goods.do")
	public String update(HttpServletResponse response,
			HttpServletRequest request, Goods goods) {
		int code=bizService.getGoodsBiz().update(goods);
		if(code>0){
			AjaxUtil.printString(response, ""+1);
		}else{
			AjaxUtil.printString(response, ""+0);
		}
		return null;
	}
	@RequestMapping(value="delById_Goods.do")
	public String delById(HttpServletResponse response,
			HttpServletRequest request, Integer id) {
		int code=bizService.getGoodsBiz().delById(id);
		if(code>0){
			AjaxUtil.printString(response, ""+1);
		}else{
			AjaxUtil.printString(response, ""+0);
		}
		return null;
	}
	@RequestMapping(value="findById_Goods.do")
	public String findById(HttpServletResponse response,
			HttpServletRequest request, Integer id) {
		Goods goods=bizService.getGoodsBiz().findById(id);
		String jsonstr=AjaxUtil.objectToJsonString(goods);
		AjaxUtil.printString(response, jsonstr);
		return null;
	}
	@RequestMapping(value="findPageAll_Goods.do")
	public String findPageAll(HttpServletResponse response,
			HttpServletRequest request, Integer page, Integer rows) {
		page=page==null||page<1?1:page;
		rows=rows==null||rows<1?5:rows;
		
		if(rows>20)rows=20;
		
		int maxrow=bizService.getGoodsBiz().findMaxRow();
		
		List<Goods> lsgoods=bizService.getGoodsBiz().findPageAll(page, rows);
		
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("page", page);
		map.put("rows", lsgoods);
		map.put("total", maxrow);
		
		
		String jsonstr=AjaxUtil.objectToJsonString(map);
		AjaxUtil.printString(response, jsonstr);
		
		
		return null;
	}
	@RequestMapping(value="findUnit_Goods.do")
	public String findUnit(HttpServletResponse response,
			HttpServletRequest request) {
		List<Unit> lsut=bizService.getUnitBiz().findAll();
		String jsonstr=AjaxUtil.objectToJsonString(lsut);
		AjaxUtil.printString(response, jsonstr);
		
		return null;
	}

}
